package indi.jp.project.business.device.controller;

import indi.jp.project.core.entity.JsonResult;
import indi.jp.project.core.util.SimpleEntityUtil;
import indi.jp.project.business.device.entity.DeviceDispatch;
import indi.jp.project.business.device.service.DeviceDispatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/yunying/deviceDispatch")
public class DeviceDispatchController {

    @Autowired
    private DeviceDispatchService deviceDispatchService;

    @GetMapping("/queryGrid")
    @ResponseBody
    public JsonResult queryGrid(@ModelAttribute DeviceDispatch entity, HttpServletRequest request) throws Exception {
        SimpleEntityUtil<DeviceDispatch> simpleEntityUtil = new SimpleEntityUtil<>();
        entity = simpleEntityUtil.setBaseEntity(entity, request);
        return deviceDispatchService.queryGrid(entity);
    }

    @PostMapping("/save")
    @ResponseBody
    public JsonResult save(@RequestBody DeviceDispatch entity, HttpServletRequest request) throws Exception {
        SimpleEntityUtil<DeviceDispatch> simpleEntityUtil = new SimpleEntityUtil<>();
        entity = simpleEntityUtil.setBaseEntity(entity, request);
        return deviceDispatchService.save(entity);

    }

    @PostMapping("/deleteById")
    @ResponseBody
    public JsonResult deleteById(HttpServletRequest request) throws Exception {
        String id = request.getParameter("id");
        return deviceDispatchService.deleteById(id);
    }

    @GetMapping("/findById")
    @ResponseBody
    public JsonResult findById(HttpServletRequest request) throws Exception {
        String id = request.getParameter("id");
        return deviceDispatchService.findById(id);
    }
}
